package com.xncoding.minispring;

import com.xncoding.minispring.Concrete.ConcreteObserver;
import com.xncoding.minispring.Concrete.ConcreteSubject;
import com.xncoding.minispring.inter.IObserver;
import com.xncoding.minispring.inter.ISubject;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.testng.annotations.Test;

public class test01 {

    @Test
    public void test01() {
        // 被观察者
        ISubject subject = new ConcreteSubject();
        // 观察者
        IObserver observer = new ConcreteObserver();
        // 将观察者注册
        subject.attach(observer);
        // 被观察者通知观察者
        subject.notify("温度从6变到7");
    }

    @Test
    public void test02() {
        ExpressionParser parser = new SpelExpressionParser();

        String str1 = parser.parseExpression("'Hello World!'").getValue(String.class);
        int int1 = parser.parseExpression("1").getValue(Integer.class);
        long long1 = parser.parseExpression("-1L").getValue(long.class);
        float float1 = parser.parseExpression("1.1").getValue(Float.class);
        double double1 = parser.parseExpression("1.1E+2").getValue(double.class);
        int hex1 = parser.parseExpression("0xa").getValue(Integer.class);
        long hex2 = parser.parseExpression("0xaL").getValue(long.class);
        boolean true1 = parser.parseExpression("true").getValue(boolean.class);
        boolean false1 = parser.parseExpression("false").getValue(boolean.class);
        Object null1 = parser.parseExpression("null").getValue(Object.class);

        System.out.println("str1=" + str1);
        System.out.println("int1=" + int1);
        System.out.println("long1=" + long1);
        System.out.println("float1=" + float1);
        System.out.println("double1=" + double1);
        System.out.println("hex1=" + hex1);
        System.out.println("hex2=" + hex2);
        System.out.println("true1=" + true1);
        System.out.println("false1=" + false1);
        System.out.println("null1=" + null1);
    }

}
